package main

import "fmt"

//#link: https://leetcode-cn.com/problems/number-complement/
func main() {
	num := 5
	fmt.Println(findComplement(num))
}

func findComplement(num int) int {
	hitBit := 0
	for i := 0; i <= 30; i++ {
		if num < 1<<uint(i) {
			break
		}
		hitBit = i
	}
	targetNum := 1<<uint(hitBit+1) - 1

	return num ^ targetNum
}
